package com.example.supplychainbackend.entity.production;

import com.example.supplychainbackend.tool.DateTimeUtils;
import jakarta.persistence.*;
import lombok.*;

import java.util.concurrent.atomic.AtomicInteger;

@Entity
@Table(name = "production_workorder")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class ProductionWorkorderEntity {
    @Id
    private String workOrderNo;

    private String planOrderNo;

    private String referenceDocType;

    private String workOrderLineNo;
    private String materialCode;
    private String materialName;
    private String materialDesc;
    private Integer workOrderQuantity;
    private String area;
    private String productionLine;
    private String processRoute;
    private String plannedStartDate;
    private String plannedEndDate;
    private Integer workOrderType;
    private Integer priority;
    private String remarks;

    private Integer reportedQuantity;

    //补充创建日期 用于溯源
    private String createDate;

    String	userName;
    String	enterpriseName;
    Boolean	onChain;
    String	transactionId;
    String	commitTime;
    String	userId;
    String	enterpriseId;

    @Transient
    private static final AtomicInteger counter = new AtomicInteger(1);

    @PrePersist
    public void generateId() {
        if (workOrderNo == null || workOrderNo.equals("")) {
            workOrderNo = String.format("%s%s%04d",
                    "WO", DateTimeUtils.getCurrentDateForID(), counter.getAndIncrement());
        }
        createDate = DateTimeUtils.getCurrentDateTime();
    }

}
